<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:insert="~{include :: header('帮助菜单列表')}" />
    <th:block th:insert="~{include :: bootstrap-table-css}" />
    <link href="/static/libs/bootstrap-treetable/bootstrap-treetable.css" rel="stylesheet" />
</head>
<body class="hold-transition">
<div class="container-fluid mb-2">
    <div class="row">
        <div class="toolbar" id="toolbar" role="group">
            <a class="btn btn-success" onclick="helpAdd()">
                <i class="fa fa-plus"></i> 新增
            </a>
            <a class="btn btn-info" id="expandAllBtn">
                <i class="fa fa-exchange"></i> 展开/折叠
            </a>
        </div>
        <div class="col-sm-12">
            <table id="bootstrap-tree-table" class="select-table table-striped"></table>
        </div>
    </div>
</div>
<th:block th:insert="~{include :: footer}" />
<th:block th:insert="~{include :: bootstrap-table-js}" />
<script src="/static/libs/bootstrap-treetable/bootstrap-treetable.js"></script>
<script th:inline="javascript">
    var prefix = "/help";
    $(function() {
        var options = {
            parentId: "parentId",
            uniqueId: "id",
            expandColumn: "1",
            url: prefix + "/list.json",
            removeUrl: prefix + "/remove/{id}",
            modalName: "帮助菜单",
            showSearch: false,
            showRefresh: true,
            showToggle: false,
            showColumns: false,
            columns: [
                {
                    field: 'selectItem',
                    radio: false,
                    visible: false
                },
                {
                    field: 'name',
                    title: '名称',
                    align: 'left', formatter: function (value, row, index) {
                        return value + " <span style='color: #DD1144'>(id:" + row.id + ")</span>"
                    }
                },
                {
                    field: 'sort',
                    title: '排序',
                    align: 'left',
                    width: '80px'
                },
                {
                    title: '操作',
                    align: 'left',
                    width: '130px',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="helpEdit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }
            ]
        };
        $.treeTable.init(options);
        // tree表格树 展开/折叠
        $("#expandAllBtn").click(function() {
            var dataExpand = $.common.isEmpty(table.options.expandAll) ? true : table.options.expandAll;
            if (!dataExpand) {
                $.bttTable.bootstrapTreeTable('expandAll');
            } else {
                $.bttTable.bootstrapTreeTable('collapseAll');
            }
            table.options.expandAll = !dataExpand;
        });
    });

    //添加
    function helpAdd() {
        $.modal.open("新增帮助菜单", prefix+"/add.html","90%","90%");
    }

    //编辑
    function helpEdit(id) {
        $.modal.open("编辑帮助菜单", prefix+"/edit/"+id,"90%","90%");
    }
</script>
</body>
</html>